<template>
  <div class="chinese-converter-page">
    <div class="converter-container">
      <h1>中文简繁体转换</h1>
      
      <div class="content-wrapper">
        <div class="input-area">
          <el-input
            v-model="inputText"
            type="textarea"
            :rows="8"
            placeholder="请输入要转换的文本"
            class="text-input"
          />
        </div>

        <div class="control-panel">
          <el-button-group>
            <el-button type="primary" @click="convertToTraditional">
              <el-icon><ArrowRight /></el-icon>
              转换为繁体
            </el-button>
            <el-button type="primary" @click="convertToSimplified">
              <el-icon><ArrowLeft /></el-icon>
              转换为简体
            </el-button>
          </el-button-group>
        </div>

        <div class="output-area">
          <el-input
            v-model="outputText"
            type="textarea"
            :rows="8"
            readonly
            placeholder="转换结果将显示在这里"
            class="text-output"
          />
          <div class="button-group">
            <el-button type="success" @click="copyResult" :disabled="!outputText">
              <el-icon><DocumentCopy /></el-icon>
              复制结果
            </el-button>
            <el-button @click="showDemo">
              <el-icon><ArrowRight /></el-icon>
              示例
            </el-button>
            <el-button type="warning" @click="returnToHome">
              <el-icon><Back /></el-icon>
              返回首页
            </el-button>
          </div>
        </div>
      </div>

      <div class="notes">
        <h3>帮助说明：</h3>
        <ul>
          <li>支持中文简体和繁体字之间的互相转换</li>
          <li>可以一键复制转换结果</li>
          <li>支持批量文本转换</li>
          <li>转换速度快，支持大量文本</li>
          <li>所有转换在本地完成，不会上传服务器</li>
          <li>适用于文章、网页等各类中文文本</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { ArrowRight, ArrowLeft, DocumentCopy, Back } from '@element-plus/icons-vue'
import { copyText } from '@/utils/clipboard'
import { s2t, t2s } from 'chinese-s2t'

const router = useRouter()
const inputText = ref('')
const outputText = ref('')

const convertToTraditional = () => {
  if (!inputText.value) {
    ElMessage.warning('请输入需要转换的文本')
    return
  }

  outputText.value = s2t(inputText.value)
  ElMessage.success('转换成功')
}

const convertToSimplified = () => {
  if (!inputText.value) {
    ElMessage.warning('请输入需要转换的文本')
    return
  }

  outputText.value = t2s(inputText.value)
  ElMessage.success('转换成功')
}

const copyResult = () => {
  if (outputText.value) {
    copyText(outputText.value)
  }
}

const showDemo = () => {
  inputText.value = '爱国'
  ElMessage.success('示例文本已加载')
}

const returnToHome = () => {
  router.push('/')
}
</script>

<style lang="scss" scoped>
.chinese-converter-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: flex-start;

  .converter-container {
    max-width: 1000px;
    width: 96%;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    padding: 30px;
    box-sizing: border-box;
    margin: 10px auto;

    h1 {
      text-align: center;
      color: #4a5568;
      font-size: 28px;
      margin-bottom: 30px;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    }

    .content-wrapper {
      .input-area, .output-area {
        margin-bottom: 20px;

        .text-input, .text-output {
          :deep(.el-textarea__inner) {
            font-family: 'Microsoft YaHei', sans-serif;
            font-size: 16px;
            line-height: 1.6;
            padding: 15px;
            border-radius: 8px;
            background-color: #f8fafc;
            border-color: #dcdfe6;
            
            &:focus {
              border-color: #409EFF;
              box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.1);
            }
          }
        }
      }

      .control-panel {
        display: flex;
        justify-content: center;
        margin: 20px 0;

        .el-button-group {
          .el-button {
            min-width: 120px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 12px 20px;
            font-size: 14px;
          }
        }
      }

      .button-group {
        display: flex;
        gap: 15px;
        margin-top: 20px;
        justify-content: center;

        .el-button {
          min-width: 120px;
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          padding: 12px 20px;
          font-size: 14px;
          border-radius: 8px;
          transition: all 0.3s ease;

          &:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
          }

          .el-icon {
            font-size: 16px;
          }
        }
      }
    }

    .notes {
      margin-top: 40px;
      padding: 20px;
      background-color: #f0f5ff;
      border-radius: 12px;
      color: #606266;
      text-align: left;

      h3 {
        color: #409EFF;
        margin: 0 0 15px 0;
        font-size: 16px;
      }

      ul {
        margin: 0;
        padding-left: 0;
        list-style-type: none;

        li {
          margin-bottom: 12px;
          line-height: 1.6;
          position: relative;
          padding-left: 18px;

          &:before {
            content: "•";
            color: #409EFF;
            font-size: 18px;
            position: absolute;
            left: 0;
            top: -2px;
          }

          &:last-child {
            margin-bottom: 0;
          }
        }
      }
    }
  }
}

@media (max-width: 768px) {
  .chinese-converter-page {
    padding: 10px;

    .converter-container {
      padding: 20px;

      h1 {
        font-size: 24px;
        margin-bottom: 20px;
      }

      .content-wrapper {
        .control-panel {
          .el-button-group {
            width: 100%;
            display: flex;

            .el-button {
              flex: 1;
            }
          }
        }

        .button-group {
          flex-direction: column;

          .el-button {
            width: 100%;
          }
        }
      }

      .notes {
        padding: 15px;

        h3 {
          font-size: 15px;
        }

        ul li {
          font-size: 13px;
          margin-bottom: 8px;
        }
      }
    }
  }
}
</style> 